﻿var OrderDetail = {
    version: '1.0.0.0.0',
    
    ListByOrder : function (orderId) {

        $('#areaOrderDetail').css('display', 'block');
        $('#toTop').click();

        $('#listOrderDetail tbody').html('<tr><td colspan="6" class="aligncenter"><img src="/images/loading.gif" alt=""/></td></tr>');
        
        var url = String.format('/GetRequest.ashx?m=orderdetail&action=listbyorder&oId={0}&rand={1}', orderId, Math.random());

        $.getJSON(url, function (res) {
            if (res != null) {
                $.Mustache.load('/templates/orderdetail/list.htm')
                    .done(function () {
                        $('#listOrderDetail tbody').html('');
                        $('#listOrderDetail tbody').mustache('tpl-order-detail-list', res);
                    });

                var urlOrder = String.format('/GetRequest.ashx?m=order&action=getorder&oId={0}', orderId);

                $.getJSON(urlOrder, function (order) {
                    if (order.Data != null) {
                        var data1 = '<div class="list plusRed floatright mr30">';
                        data1 += '<ul>';                        
                        data1 += String.format('<li>Tổng tiền: {0} (VND)</li>', order.Data.TotalOrderMoney);
                        data1 += String.format('<li>Giảm giá: {0}</li>', order.Data.Discount);
                        data1 += String.format('<li>Giảm giá: {0}</li>', order.Data.Percent);
                        data1 += '</ul>';
                        data1 += '</div>';

                        var data2 = '<div class="list plusBlue floatright mr10">';
                        data2 += '<ul>';                        
                        data2 += String.format('<li>Tình trạng: {0}</li>', order.Data.OrderStatus);
                        data2 += String.format('<li>Ngày trả hàng: {0}</li>', order.Data.FormatRequiredDate);
                        data2 += String.format('<li>Ghi chú: {0}</li>', order.Data.Note);
                        data2 += '</ul>';
                        data2 += '</div>';
                        
                        var html = String.format('<tr><td colspan="6">{0}</td></tr>', data2 + data1);
                        $('#listOrderDetail tbody').append(html);    
                    }                    
                });                                
            }
        });
        
    }

};